﻿using System;
using System.Data.OleDb;
using System.Data;
using System.Collections;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Net;
using System.IO;
using Newtonsoft.Json;

namespace QuanLyNhanVien.DataAccessLayer
{
    public class DataProvider
    {

        static public string URL = "http://localhost:7618";
        
        protected ArrayList ConvertDataSetToArrayList(DataSet dataset)
        {
            
            ArrayList arr = new ArrayList();
            DataTable dt = dataset.Tables[0];
            int i, n = dt.Rows.Count;
            for (i = 0; i < n; i++)
            {
                object obj = GetDataFromDataRow(dt, i);
                arr.Add(obj);

            }
            
            return arr;
        }

        protected virtual object GetDataFromDataRow(DataTable dt, int i)
        {
            return null;
        }
        public List<string> ListTables()
        {
            List<string> result = new List<string>();

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL + "/api/Tables");
            request.Method = "GET";
            request.ContentType = "application/json";

            try
            {
                WebResponse webResponse = request.GetResponse();
                using (Stream webStream = webResponse.GetResponseStream())
                {
                    if (webStream != null)
                    {
                        using (StreamReader responseReader = new StreamReader(webStream))
                        {

                            string response = responseReader.ReadToEnd();
                            result = JsonConvert.DeserializeObject<List<string>>(response);

                        }
                    }
                }
            }
            catch (Exception e)
            {
            }

            return result;
        }
    }
}
